package com.example.prom.utils;

import org.apache.http.client.HttpClient;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;

public class HttpClientSingleton {

//    private static class AmplitudeHttpClientHolder {
//        private static HttpClient amplitudeHttpClient = HttpClients.custom()
//                .setRetryHandler(new DefaultHttpRequestRetryHandler())
//                .setDefaultRequestConfig(RequestConfig.custom()
//                        .setSocketTimeout(2000)
//                        .setConnectTimeout(2000)
//                        .setConnectionRequestTimeout(2000)
//                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
//                        .build())
//                .setServiceUnavailableRetryStrategy(new AmplitudeRetryStrategy())
//                .setMaxConnTotal(60)
//                .setMaxConnPerRoute(60)
//                .build();
//    }
//    public static HttpClient getAmplitudeHttpClient() {
//        return AmplitudeHttpClientHolder.amplitudeHttpClient;
//    }

    private static class HubspotHttpClientHolder {
        private static HttpClient hubspotHttpClient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(4000)
                        .setConnectTimeout(4000)
                        .setConnectionRequestTimeout(4000)
                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                        .build())
                .setMaxConnTotal(40)
                .setMaxConnPerRoute(40)
                .build();
    }
    public static HttpClient getHubspotHttpClient() {
        return HubspotHttpClientHolder.hubspotHttpClient;
    }

    private static class AppsflyerHttpClientHolder {
        private static HttpClient appsflyerHttpClient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(2000)
                        .setConnectTimeout(2000)
                        .setConnectionRequestTimeout(2000)
                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                        .build())
                .setMaxConnTotal(20)
                .setMaxConnPerRoute(20)
                .build();
    }
    public static HttpClient getAppsflyerHttpClient() {
        return AppsflyerHttpClientHolder.appsflyerHttpClient;
    }

    private static class OnesignalHttpClientHolder {
        private static HttpClient onesignalHttpClient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(2000)
                        .setConnectTimeout(2000)
                        .setConnectionRequestTimeout(2000)
                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                        .build())
                .setMaxConnTotal(20)
                .setMaxConnPerRoute(20)
                .build();
    }
    public static HttpClient getOnesignalHttpClient() {
        return OnesignalHttpClientHolder.onesignalHttpClient;
    }

    private static class CustomHttpClientHolder {
        private static HttpClient customHttpClient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(3000)
                        .setConnectTimeout(3000)
                        .setConnectionRequestTimeout(3000)
                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                        .build())
                .setMaxConnTotal(100)
                .setMaxConnPerRoute(50)
                .build();
    }
    public static HttpClient getCustomHttpClient() {
        return CustomHttpClientHolder.customHttpClient;
    }

    private static class LongCustomHttpClientHolder {
        private static HttpClient longCustomHttpClient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(25000)
                        .setConnectTimeout(25000)
                        .setConnectionRequestTimeout(25000)
                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                        .build())
                .setMaxConnTotal(100)
                .setMaxConnPerRoute(50)
                .build();
    }
    public static HttpClient getLongCustomHttpClient() {
        return LongCustomHttpClientHolder.longCustomHttpClient;
    }

    private static class PushHttpClientHolder {
        private static HttpClient pushHttpClient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(9000)
                        .setConnectTimeout(9000)
                        .setConnectionRequestTimeout(9000)
                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                        .build())
                .setMaxConnTotal(100)
                .setMaxConnPerRoute(50)
                .build();
    }
    public static HttpClient getPushHttpClient() {
        return PushHttpClientHolder.pushHttpClient;
    }

    private static class FaceHttpClientHolder {
        private static HttpClient faceHttpClient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(9000)
                        .setConnectTimeout(9000)
                        .setConnectionRequestTimeout(9000)
                        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                        .build())
                .setMaxConnTotal(30)
                .setMaxConnPerRoute(15)
                .build();
    }
    public static HttpClient getFaceHttpClient() {
        return FaceHttpClientHolder.faceHttpClient;
    }

}